package com.rupertjones.globalcron.resources;

import org.brownflat.dbinit.upgrade.Upgrade;
import org.springframework.stereotype.Component;

/**
 * <p>&copy Rupert Jones 2011,2012</p>
 *
 * @author rup
 */
@Component
public class Upgrade0012CreateHost implements Upgrade {
    @Override
    public int getSequence() {
        return 12;
    }

    @Override
    public String getSql() {
        return "ALTER TABLE `job`\n" +
                "DROP COLUMN `hostname`;\n" +
                "\n" +
                "ALTER TABLE `job`\n" +
                "ADD COLUMN `host` INT NOT NULL DEFAULT 0;\n" +
                "\n" +
                "CREATE TABLE `host` (\n" +
                "  `id` int(11) NOT NULL AUTO_INCREMENT,\n" +
                "  `name` varchar(255) NOT NULL,\n" +
                "  `hostname` varchar(255) NOT NULL,\n" +
                "  PRIMARY KEY (`id`),\n" +
                "  UNIQUE KEY `hostname_UNIQUE` (`hostname`)\n" +
                ") ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=latin1;";
    }

    @Override
    public String getName() {
        return "Create Host";
    }
}
